/** 
* 文 件 名:XmlHelper.java
* Copyright (C) 2007-2012:杭州希禾信息技术有限公司 版权所有 
* 创 建 人:Administrator
* 日    期:2012-3-13 下午1:28:14
* 修 改 人: 
* 日   期:
* 修改描述:
* 描   述:TODO
*/
package net.seehealth.healthpad.application.util;

import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import java.util.HashMap;
import java.util.Map.Entry;

import net.seehealth.healthpad.utils.StringUtils;

/**
 * @className XmlHelper
 * @author Administrator
 * @description TODO
 * @date 2012-3-13 下午1:28:14
 */
public  class DataServiceHelper {
	
	private DataServiceHelper()
	{
		
	}
	
	/**
	  * @description:简单生成soap格式的xml请求体
	  * @param methodName:webService方法名 params:參數鍵值對
	  * @return 
	  * @throws Exception   
	  * @author 林洪波
	  * @date 2012-3-13 下午2:21:38
	  */
	public static String genSimpleSoapContent(String methodName,HashMap<String,String> params)
	{
		StringBuilder sb=new StringBuilder();
		sb.append("<?xml version=\"1.0\" encoding=\"utf-8\"?>");
		sb.append("<soap12:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap12=\"http://www.w3.org/2003/05/soap-envelope\" >");
		sb.append("<soap12:Body>");
		methodName=methodName.substring(0,1).toUpperCase()+methodName.substring(1);
		sb.append("<"+methodName+" xmlns=\"http://tempuri.org/\">");
		for(Entry<String,String> entry:params.entrySet())
		{
			sb.append("<"+entry.getKey()+">"+entry.getValue()+"</"+entry.getKey()+">");
		}
		sb.append("</"+methodName+">");
		sb.append("</soap12:Body>");
		sb.append("</soap12:Envelope>");
		return sb.toString();
	}
	
	
	/**
	  * @description:简单生成soap格式的xml请求体
	  * @param methodName:webService方法名 paramName:參數名 paramValue:參數值
	  * @return 
	  * @throws Exception   
	  * @author 林洪波
	  * @date 2012-3-13 下午3:30:18
	  */
	public static String genSimpleSoapContent(String methodName,String paramName,String paramValue)
	{
		HashMap<String,String> params=new HashMap<String, String>();
		if("".equals(paramName)||paramName==null||"".equals(paramValue)||paramValue==null)
		{
			
		}
		else
		{
			params.put(paramName,paramValue);
		}
		return genSimpleSoapContent(methodName,params);
	}
	
	/**
	  * @description:返回二进制数据
	  * @param 
	  * @return 
	  * @throws Exception   
	  * @author 林洪波
	  * @date 2012-3-12 下午6:16:57
	  */
	public static byte[] readInputStream(InputStream inStream) throws Exception{
		ByteArrayOutputStream outStream = new ByteArrayOutputStream();
		byte[] buffer = new byte[1024];
		int len = 0;
		while( (len=inStream.read(buffer)) != -1 ){
			outStream.write(buffer, 0, len);
		}
		inStream.close();
		return outStream.toByteArray();
	}
	
}
